import * as mongoose from 'mongoose';

export const AuthTicketSchema = new mongoose.Schema({
  corpId: { type: String, index: true },
  authCode: { type: String, index: true },
  preAuthCode: String,
  state: String,
  authUserInfo: { type: mongoose.Schema.Types.Mixed, required: false },
  expiresAt: Date,
  status: { type: Number, default: 1 }, // 1-有效 2-已使用 3-已过期
  teamId: Number,
  create_time: { type: Number, default: () => Date.now() },
}, {
  collection: 'auth_tickets',
  timestamps: { currentTime: () => Date.now() }
});

// 添加索引
AuthTicketSchema.index({ authCode: 1 });
AuthTicketSchema.index({ corpId: 1 });
AuthTicketSchema.index({ status: 1 });
AuthTicketSchema.index({ expiresAt: 1 });
AuthTicketSchema.index({ create_time: -1 });